/**
 * 警告弹窗;
 */

const { ccclass, property } = cc._decorator;
@ccclass
export default class ScreenClick extends cc.Component {
	@property(cc.Prefab)
	animaPrefab: cc.Prefab = null;

	@property(cc.Node)
	particleNode: cc.Node = null;

	touchListener = null;
	_nodePool: cc.NodePool = null;
	onLoad() {
		this._nodePool = new cc.NodePool();

		this.node.on(cc.Node.EventType.TOUCH_START, this.touchStart.bind(this), this);
		this.node._touchListener.swallowTouches = false;

		var node = cc.instantiate(this.animaPrefab);
		node.parent = this.particleNode;
		node.active = false;
	}

	touchStart(event) {
		var _node;
		if (this._nodePool.size() > 0) {//取缓存
			_node = this._nodePool.get();
		} else {//实例化一个新的
			_node = cc.instantiate(this.animaPrefab);
		}
		_node.parent = this.particleNode;

		var _point = this.particleNode.convertToNodeSpaceAR(event.getLocation())
		_node.position = _point;
		var anime = _node.getComponent(cc.Animation);
		anime.on('finished', this.AnimeEnd, this);
		anime.play();

		_node.children[1].getComponent("cc.ParticleSystem").resetSystem();

		//	console.log("screenClick TouchBegan");
		return false;
	}

	AnimeEnd(name, aniState) {
		var _node = aniState._target.node;
		if (_node) {
			this._nodePool.put(_node);
		}

	}

}
